<?php

namespace app\controller\api;

use app\base\BaseEncryptController;
use app\factory\LoginUser;
use app\factory\User as UserFacade;
use app\factory\wxPay\WxParam;
use app\libs\AliyunSms;
use app\libs\Util;
use app\model\business\BusinessModel;
use app\model\game\GameProcessModel;
use app\model\order\OrderModel;
use app\model\store\StoreDepositModel;
use app\model\store\StoreModel;
use app\model\system\LogisticsModel;
use app\model\system\SysConfigModel;
use app\model\user\UserLevelModel;
use app\model\user\UserMarketModel;
use app\model\user\UserMemberModel;
use app\model\user\UserModel;
use app\model\user\UserParentModel;
use app\model\user\UserSmsCodeModel;
use app\model\user\UserSuggestModel;
use think\Request;

/**
 * User
 * Class User
 * @package app\controller
 */
class User extends BaseEncryptController
{
    protected function initialize()
    {
        parent::initialize();
        $this->model = new UserModel();
    }

    /**
     * 获取推广用户列表
     * @param string $status
     * @param string $keyword
     * @param int $sex
     * @param int $page
     * @param int $limit
     * @param string $user_id
     * @return \think\response\Json
     */
    public function getPopPage($status = '', $keyword = '', $sex = 3, $page = 1, $limit = 10, $user_id = '')
    {
        $data = $this->model->getPopPageData($status, $keyword, $sex, $page, $limit, '*', $user_id);
        return self::returnMsg(1, [
            'totalCount' => $data['total'],
            'currentPage' => $data['current'],
            'pageList' => $data['dataList']
        ]);
    }

    /**
     * 用户登录-获取session
     * @param $code
     * @param $top_code
     * @param $type
     * @param $appid
     * @return \think\response\Json
     */
    public function onWxSessionKey($code = '', $top_code = '', $type = 'every', $appid = '')
    {
        $LoginUser = new LoginUser($appid);
        $data = $LoginUser->getWxSessionKey($code, $type);
        return self::returnMsg($data);
    }

    /**
     * 获取验证码
     * @param string $phone
     * @return \think\response\Json
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public function getVerifyCode($phone = '')
    {
        $code = rand(100000, 999999);
        $addr_ip = Util::get_real_ip();
        $data = AliyunSms::sendSms($phone, $code, $addr_ip);
        if ($data['code'] == 1) {
            //添加验证码获取记录
            UserSmsCodeModel::addCode($phone, $code);
        }
        return self::returnMsg($data);
    }

    /**
     * 验证短信验证码
     * @param string $phone
     * @param string $code
     * @param string $top_code
     * @param string $name
     * @param string $head_img
     * @param string $openid
     * @return \think\response\Json
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public function onLoginPhone($phone = '', $code = '', $top_code = '', $name = '', $head_img = '', $openid = "")
    {
        $data = $this->model->loginPhone($phone, $code, $top_code, $name, $head_img, $openid);
        return self::returnMsg($data);
    }

    /**
     * 更新头像和昵称
     * @param string $name
     * @param string $head_img
     * @return \think\response\Json
     */
    public function onUpdateUserWx($name = '', $head_img = '')
    {
        $user_id = $this->currentUser['user_id'];
        $up_data = [
            'nick_name' => $name,
            'head_img' => $head_img,
            'update_time' => time()
        ];
        $user_model = new UserModel();
        $user_model->where('id', $user_id)->update($up_data);
        $data = [
            'code' => 1,
            'msg' => "修改成功"
        ];
        return self::returnMsg($data);
    }

    /**
     * 用户登录-token
     * @param Request $request
     * @return \think\response\Json
     */
    public function onLogin(Request $request)
    {
        $LoginUser = new LoginUser();
        $param = $request->param();
        file_put_contents("param.text", json_encode($param));
        $data = $LoginUser->login($request->param());
        return self::returnMsg($data);
    }

    /**
     * 个人中心
     * @param Request $request
     * @return \think\response\Json
     */
    public function onUserCore(Request $request)
    {
        $formData = $request->param();
        $type = isset($formData['type']) ? $formData['type'] : "user";
        if ($type == 'system') {
            $res = [
                'code' => 1,
                'data' => [
                    'status' => 'ok'
                ],
                'msg' => "未开启"
            ];
            return self::returnMsg($res);
        }
        $userInfo = $this->currentUser;//登录信息
        if (!isset($userInfo['user_id'])) {
            $res = [
                'code' => 1,
                'data' => []
            ];
            return self::returnMsg($res);
        }

        $UserFacade = new UserFacade();
        $res = $UserFacade->userCore($formData, $userInfo);
        if ($type == 'pop') {
            if (isset($res['data']['userInfos'])) {
                $wx_param = new WxParam();
                $code = $res['data']['userInfos']['popularize_code'];
                $path = "pages/index/index";
                $url = $wx_param->getSceneQrcode('0_' . $code, $path);
                $url = substr($url, 2, strlen($url));
                $res['data']['userInfos']['popUrl'] = $url;
            }

        }
        $res['data']['status'] = 'ok';

        return self::returnMsg($res);
    }

    /**
     * 获取佣金情况
     * @param Request $request
     */
    public function getUserMoney(Request $request)
    {
        $formData = $request->param();
        $userInfo = $this->currentUser;//登录信息
        $UserFacade = new UserFacade();
        $res = $UserFacade->getUserMoney($formData, $userInfo);
        return self::returnMsg($res);
    }

    /**
     * 获取规则
     * @param string $type
     * @return \think\response\Json
     */
    public function getRule($type = '1')
    {
        $rule = "规则";
        switch (intval($type)) {
            case 1:
                //积分规则
                $sys_data = SysConfigModel::getSystem();
                $rule = $sys_data['integral_rule'];
                break;
            case 2:
                //用户收益规则
                $sys_data = SysConfigModel::getSystem();
                $rule = $sys_data['user_earnings_rule'];
                break;
            case 3:
                $sys_data = SysConfigModel::getSystem();
                $rule = $sys_data['agency_earnings_rule'];
                break;
        }
        $data['rule'] = $rule;
        return self::returnMsg(1, $data, '获取成功');
    }

    /**
     * 用户积分记录
     * @param Request $request
     * @return \think\response\Json
     */
    public function onUserIntegral(Request $request)
    {
        $formData = $request->param();
        $userInfo = $this->currentUser;//登录信息
        $UserFacade = new UserFacade();
        $res = $UserFacade->userIntegral($formData, $userInfo);
        return self::returnMsg($res);
    }

    /**
     * 用户积分记录
     * @param Request $request
     * @return \think\response\Json
     */
    public function onUserBalanceLog(Request $request)
    {
        $formData = $request->param();
        $userInfo = $this->currentUser;//登录信息
        $UserFacade = new UserFacade();
        $res = $UserFacade->userBalance($formData, $userInfo);
        return self::returnMsg($res);
    }

    /**
     * 用户收益
     * @param Request $request
     * @return \think\response\Json
     */
    public function onUserEarnings(Request $request)
    {
        $formData = $request->param();
        $userInfo = $this->currentUser;//登录信息
        $UserFacade = new UserFacade();
        $res = $UserFacade->userEarnings($formData, $userInfo);
        return self::returnMsg($res);
    }

    /**
     * 用户收益提现
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function onUserEarningsExtract(Request $request)
    {
//        $data = [
//            'pay_sn' => "extract" . date("YmdHis"),
//            'pay_amount' => 0.01,
//            'openid' => "oRLHh4vRnew39ifwctuYnMNujaF0",
//        ];
//        $factory_company_pay = new CompanyPay();
//        print_r($data);
//        $wx_res = $factory_company_pay->confirm_pay($data);
//        print_r($wx_res);
        $price = $request->param('price');
        $openid = $request->param('openid');
        $userInfo = $this->currentUser;//登录信息
        $UserFacade = new UserFacade();

        $out_data['code'] = 0;
        $out_data['msg'] = "账户金额不足";
        return self::returnMsg($out_data);
        $w = date("w");
        if ($w == 6 || $w == 0) {
            $out_data['code'] = 0;
            $out_data['msg'] = "提现时间(周一到周五)";
            return self::returnMsg($out_data);
        }
        $res = $UserFacade->userEarningsExtract($price, $userInfo, $openid);
        return self::returnMsg($res);
    }

    /**
     * 获取物流列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getLogisticsList()
    {
        $logistics_model = new LogisticsModel();
        $map = [
            'status' => 0
        ];
        $logistics_list = $logistics_model->getAll($map, 'logistics_name,logistics_code');
        $logistics_list_arr[] = [
            'logistics_name' => "请选择快递公司",
            'logistics_code' => "",
        ];
        foreach ($logistics_list as $value) {
            $logistics_list_arr[] = $value;
        }
        $rsps['code'] = 1;
        $rsps['data'] = $logistics_list_arr;
        return self::returnMsg($rsps);
    }

    /**
     * 开通vip展示
     * @param Request $request
     * @return \think\response\Json
     */
    public function getUserVip()
    {
        $user_level_model = new UserLevelModel();
        $res = $user_level_model->vipList();
        return self::returnMsg($res);
    }

    /**
     *提交意见反馈
     * @param Request $request
     * @return \think\response\Json
     */
    public function onSuggest(Request $request)
    {
        $res['code'] = 0;
        $res['msg'] = "提交失败";
        $suggest = $request->param('suggest');
        if (empty($suggest)) {
            $res['code'] = 0;
            $res['msg'] = "参数有误";
        } else {
            $in_suggest = [
                'user_id' => $this->currentUser['user_id'],
                'content' => $suggest,
                'add_time' => time()
            ];
            $user_suggest_model = new UserSuggestModel();
            $ret = $user_suggest_model->save($in_suggest);
            if ($ret !== false) {
                $res['code'] = 1;
                $res['msg'] = "提交成功";
            }
        }
        return self::returnMsg($res);
    }

    /**
     * 申请成为推广员
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function onMarket(Request $request)
    {
        $res['code'] = 0;
        $res['msg'] = "提交失败";
        $explain = $request->param('explain');
        $phone = $request->param('phone');
        $wechat = $request->param('wechat');
        if (!Util::isMobileNumber($phone)) {
            $res['code'] = 0;
            $res['msg'] = "手机号码格式不正确";
            return self::returnMsg($res);
        }
        if (empty($explain) || empty($phone) || empty($wechat)) {
            $res['code'] = 0;
            $res['msg'] = "参数有误";
        } else {
            $ret = UserMarketModel::addMarket($this->currentUser['user_id'], $explain, $phone, $wechat, 1);
            if ($ret !== false) {
                $res['code'] = 1;
                $res['msg'] = "提交成功";
            }
        }
        return self::returnMsg($res);
    }

    /**
     * 获取申请成为推广员信息
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMarket()
    {
        $user_market_model = new UserMarketModel();
        $map = [
            'user_id' => $this->currentUser['user_id']
        ];
        $market = $user_market_model->where($map)->find();
        if (empty($market)) {
            $res['code'] = 0;
            $res['data'] = [];
            $res['msg'] = "请填写数据";
            return self::returnMsg($res);
        }
        $res['code'] = 1;
        $res['data'] = $market;
        $res['msg'] = "获取成功";
        return self::returnMsg($res);
    }

    /**
     * 商家申请入驻
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function onSettled(Request $request)
    {
        $res['code'] = 0;
        $res['msg'] = "提交失败";
        $phone = $request->param('phone');
        $wechat = $request->param('wechat');
        $area = $request->param('area');
        $store_type = $request->param('store_type');
        $card_photo = $request->param('card_photo');
        $store_name = $request->param('store_name');
        $store_label = $request->param('store_label');
        $store_scope = $request->param('store_scope');
        $store_desc = $request->param('store_desc');
        $top_popularize_code = $request->param('top_popularize_code');
        if (!Util::isMobileNumber($phone)) {
            $res['msg'] = "手机号码不正确";
            return self::returnMsg($res);
        }
        if (empty($wechat) || empty($area) || empty($card_photo) || empty($store_name) || empty($store_label) || empty($store_scope) || empty($store_desc)) {
            $res['msg'] = "提交数据有误";
            return self::returnMsg($res);
        }
        $store_model = new StoreModel();
        $store = $store_model->where('contact_phone', $phone)->find();
        if (!empty($store) && $store['user_id'] != $this->currentUser['user_id']) {
            $res['code'] = 0;
            $res['msg'] = "该手机号码已被申请";
            return self::returnMsg($res);
        } else {
            $map = [
                'user_id' => $this->currentUser['user_id']
            ];
            $store = $store_model->where($map)->find();
        }
        $store_top = 0;
        $store_top_temp = $store_model->where(['popularize_code' => $top_popularize_code])->field('id')->find();
        if (empty($store_top_temp)) {
            $store_top = $store_top_temp['id'];
        }
        $ret = false;
        if (empty($store)) {
            $len = 11 - strlen($store['user_id']);
            $popularize_code = Util::getRandomString($len) . $store['user_id'];
            $in_store = [
                'user_id' => $this->currentUser['user_id'],
                'grade_id' => 2,
                'store_name' => $store_name,
                'store_label' => $store_label,
                'store_type' => $store_type,
                'contact_phone' => $phone,
                'store_desc' => $store_desc,
                'store_scope' => $store_scope,
                'card_photo' => $card_photo,
                'contact_wechat' => $wechat,
                'store_top' => $store_top,
                'popularize_code' => $popularize_code,
                'store_area' => $area,
            ];
            $ret = $store_model->save($in_store);
        } else {
            if (intval($store['check_status']) == 2) {
                $up_store = [
                    'id' => $store['id'],
                    'user_id' => $this->currentUser['user_id'],
                    'store_name' => $store_name,
                    'store_label' => $store_label,
                    'store_type' => $store_type,
                    'contact_phone' => $phone,
                    'store_desc' => $store_desc,
                    'store_scope' => $store_scope,
                    'card_photo' => $card_photo,
                    'contact_wechat' => $wechat,
                    'store_area' => $area,
                    'check_status' => 0
                ];
                $ret = $store_model->saveData($up_store);
            }
        }
        if ($ret !== false) {
            $res = [
                'code' => 1,
                'msg' => "提交成功"
            ];
        }
        return self::returnMsg($res);
    }

    /**
     * 获取商家申请入驻信息
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSettled()
    {
        $map = [
            'user_id' => $this->currentUser['user_id']
        ];
        $store_model = new StoreModel();
        $store = $store_model->where($map)->find();
        if (!empty($store)) {
            $store = $store->toArray();
            if (strpos($store['card_photo'], ',') > 0) {
                $store['card_photo_arr'] = explode(',', $store['card_photo']);
            } else {
                $store['card_photo_arr'][] = $store['card_photo'];
            }
            $top_popularize_code = "";
            if (!empty($store['store_top'])) {
                $store_top_temp = $store_model->where('id', $store['store_top'])->field('id')->find();
                if (!empty($store_top_temp)) {
                    $top_popularize_code = $store_top_temp['popularize_code'];
                }
            }
            $store['top_popularize_code'] = $top_popularize_code;
            $basic = $store;
            StoreModel::formatx($basic);
            if (empty($basic['real_name'])) {
                $basic['real_name'] = "***";
            } else {
                $basic['real_name'] = mb_substr($basic['real_name'], 0, 1) . ((mb_strlen($basic['real_name'])) > 2 ? '**' : '*');
            }
            $store['basic'] = $basic;

        } else {
            $store = [];
        }
        $res = [
            'code' => 1,
            'data' => $store,
            'msg' => "获取成功",
        ];
        return self::returnMsg($res);
    }

    /**
     * 缴纳店铺保证金
     * @return \think\response\Json
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function storeDeposit()
    {
        $res = [
            'code' => 0,
            'msg' => "店铺数据有误",
        ];
        $store_model = new StoreModel();
        $store = $store_model->where('user_id', $this->currentUser['user_id'])->field('id,store_deposit,check_status')->find();
        if (empty($store)) {
            return self::returnMsg($res);
        }
        if (intval($store['check_status']) != 1) {
            $res = [
                'code' => 0,
                'msg' => "店铺未审核通过，无法缴纳保证金",
            ];
            return self::returnMsg($res);
        }
        if (floatval($store['store_deposit']) > 0) {
            $res = [
                'code' => 0,
                'msg' => "保证金不得重复缴纳",
            ];
            return self::returnMsg($res);
        }
        $store_deposit_model = new StoreDepositModel();
        $sys_config = SysConfigModel::getSystem();
        $deposit = $sys_config['deposit'];//保证金
        $pay_info = $store_deposit_model->addDepositPayInfo($store['id'], $this->currentUser['user_id'], floatval($deposit));
        $res = [
            'code' => 1,
            'data' => $pay_info,
            'msg' => "获取成功"
        ];
        return self::returnMsg($res);
    }

    /**
     * 绑定推广用户
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function onUserTop(Request $request)
    {
        $res = [
            'code' => 0,
            'msg' => "绑定失败"
        ];
        $code = $request->param('code');
        $userInfo = $this->currentUser;//登录信息
        $user_id = $userInfo['user_id'];
        if ($code == "") {
            $res['msg'] = "推广码不能为空";
            return self::returnMsg($res);
        }
        $UserModel = new UserModel();
        $top_info = $UserModel->where("popularize_code", $code)->field("id")->find();
        if (!isset($top_info['id'])) {
            $res['msg'] = "上级不存在";
            return self::returnMsg($res);
        }
        if ($top_info['id'] == $user_id) {
            $res['msg'] = "推荐人不能是自己";
            return self::returnMsg($res);
        }
        $tup_user['id'] = $user_id;
        $tup_user['top_user_id'] = $top_info['id'];//上级id
        $tup_user['top_time'] = date("Y-m-d H:i:s");//更新时间
        $ret = $UserModel->update($tup_user);
        $UserModel->popularizeCount($user_id);
        if ($ret !== false) {
            $res = [
                'code' => 1,
                'msg' => "绑定成功"
            ];
            $user_parent_model = new UserParentModel();
            $user_parent_model->addParent($user_id);
            UserParentModel::upChildrenSubset($top_info['id']);
        }
        return self::returnMsg($res);
    }

    /**
     * 获取推广列表
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function getUserPopList(Request $request)
    {
        $formData = $request->param();
        $userInfo = $this->currentUser;//登录信息
        $page = $formData['page'];
        $limit = $formData['limit'];
        $type = $formData['type'];
        if (isset($formData['day'])) {
            if (!empty($formData['day'])) {
                $day = $formData['day'];
            } else {
                $day = date("Y-m-d");
            }
        } else {
            $day = date("Y-m-d");
        }
        $lose = $formData['lose'];
        if ($type == 0) {
            $user_model = new UserModel();
            $dataList = $user_model
                ->where('top_user_id', $userInfo['user_id'])
                ->field("id,member_level,phone,top_time")
                ->order('top_time DESC')
                ->paginate(['page' => $page, 'list_rows' => $limit], false);
            $items = $dataList->items();
            $user_ids = [];
            foreach ($items as &$value) {
                $user_ids[] = $value['id'];
            }
            $time_start = strtotime($day);
            $time_ene = strtotime($day . " 23:59:59");
            if (empty($lose)) {
                $order_model = new OrderModel();
                $user_data = $order_model->getUserListPop($user_ids, $time_start, $time_ene);
                $user_all_data = $order_model->getUserListPopSum($user_ids);
            } else {
                $user_data = GameProcessModel::getUserListPop($user_ids, $time_start, $time_ene);
                $user_all_data = GameProcessModel::getUserListPopSum($user_ids);
            }
            $all_total = 0;
            $day_total = 0;
            $all_sum = $user_model->where('top_user_id', $userInfo['user_id'])->count();
            $items_arr = json_decode(json_encode($items), true);
            foreach ($items_arr as &$value) {
                $value['phone'] = Util::swPhoneStr($value['phone']);
                $value['total'] = $user_all_data[intval($value['id'])]['total'];
                $value['day_total'] = $user_data[intval($value['id'])]['total'];
                $value['level'] = UserModel::getLevel($value['member_level']);
                $value['order_ids'] = $user_data[intval($value['id'])]['order_ids'];
                $all_total += floatval($value['total']);
                $day_total += floatval($value['day_total']);
            }
            Util::listOrder($items_arr, 'total', 'desc');
            return self::returnMsg(1, [
                'totalCount' => $all_sum,
                'totalCost' => round($all_total, 2),
                'dayCost' => round($day_total, 2),
                'pageList' => $items_arr
            ]);
        } else {
//            $out_data_str = Cache::get('team_' . $page . 'all_' . $userInfo['user_id']);
//            $out_data = json_decode($out_data_str, true);
//            if (empty($out_data)) {
//                $out_data = UserParentModel::getTeamAll($userInfo['user_id'], $page, $limit,$lose);
//                Cache::set('team_' . $page . 'all_' . $userInfo['user_id'], json_encode($out_data), 600);
//            }
            $out_data = UserParentModel::getTeamAll($userInfo['user_id'], $page, $day, $limit, $lose);
            $data = [
                'totalCount' => $out_data['all_total'],
                'totalCost' => round($out_data['sum_all'], 2),
                'dayCost' => round($out_data['day_all'], 2),
                'pageList' => $out_data['list']
            ];
            return self::returnMsg(1, $data);
        }
    }

    /**
     * 申请成为会员
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function onMember(Request $request)
    {
        $res['code'] = 0;
        $res['msg'] = "提交失败";
        $popularize_code = $request->param('popularize_code');
        $group_name = $request->param('group_name');
        $photo = $request->param('photo');
        if (empty($popularize_code) || empty($group_name) || empty($photo)) {
            $res['code'] = 0;
            $res['msg'] = "参数有误";
        } else {
            $ret = UserMemberModel::addMember($this->currentUser['user_id'], $popularize_code, $group_name, $photo);
            if ($ret !== false) {
                $res['code'] = 1;
                $res['msg'] = "提交成功";
            }
        }
        return self::returnMsg($res);
    }

    /**
     * 获取申请成为会员信息
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMember()
    {
        $user_member_model = new UserMemberModel();
        $map = [
            'user_id' => $this->currentUser['user_id']
        ];
        $member = $user_member_model->where($map)->find();
        if (empty($member)) {
            $res['code'] = 0;
            $res['data'] = [];
            $res['msg'] = "请填写数据";
            return self::returnMsg($res);
        }
        $member['photo_arr'] = explode(',', $member['photo']);
        $res['code'] = 1;
        $res['data'] = $member;
        $res['msg'] = "获取成功";
        return self::returnMsg($res);
    }

    /**
     * 提交商家认证信息
     * @param Request $request
     */
    public function addBusiness(Request $request)
    {
        $res['code'] = 0;
        $res['msg'] = "提交失败";
        $name = $request->param('name');
        $storefront = $request->param('storefront');
        $address = $request->param('address');
        $contact_name = $request->param('contact_name');
        if (empty($name) || empty($storefront) || empty($address) || empty($contact_name)) {
            $res['code'] = 0;
            $res['msg'] = "参数有误";
        } else {
            $contact_phone = UserModel::getPhone($this->currentUser['user_id']);
            $ret = BusinessModel::addBusiness($this->currentUser['user_id'], $name, $storefront, $contact_name, $contact_phone, $address);
            if ($ret !== false) {
                $res['code'] = 1;
                $res['msg'] = "提交成功";
            }
        }
        return self::returnMsg($res);
    }

    /**
     * 获取商家认证信息
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getBusiness()
    {
        $map = [
            'user_id' => $this->currentUser['user_id']
        ];
        $business_model = new BusinessModel();
        $business = $business_model->where($map)->find();
        if (empty($business)) {
            $res['code'] = 1;
            $res['data'] = [];
            $res['msg'] = "请填写数据";
            return self::returnMsg($res);
        }
        $res['code'] = 1;
        $res['data'] = $business;
        $res['msg'] = "获取成功";
        return self::returnMsg($res);
    }
}
